Skip to content

valueflow.cpp: avoid some copies related to ErrorPath#4160

Merged
firewave merged 1 commit into
cppcheck-opensource:mainfrom
firewave:errorpath
Jul 20, 2022
Merged

valueflow.cpp: avoid some copies related to ErrorPath#4160
firewave merged 1 commit into
cppcheck-opensource:mainfrom
firewave:errorpath

Conversation

@firewave
Copy link
Copy Markdown
Collaborator

@firewave firewave commented Jun 1, 2022

Testing an -O2 build with --enable=all --inconclusive on mame_regtest code (with some additional local speed hacks and Boost SmallVector applied):
Clang 13 18,349,224,671 -> 18,347,635,685

We might also be able to use std::move() in addErrorPath() and reanalyze().

Comment thread lib/valueflow.cpp
ErrorPath er = v.errorPath;
const Variable *var = getLifetimeVariable(tok2, er);
// TODO: the inserted data is never used
er.insert(er.end(), errorPath.begin(), errorPath.end());
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfultz2
Please take a look. Seems like this is inserted the wrong way.

Would be great if we could detect this but I guess it's a variant of https://trac.cppcheck.net/ticket/4593.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfultz2 Please take a look.

Feel free to merge as well.

Comment thread lib/valueflow.cpp
value.lifetimeScope = ValueFlow::Value::LifetimeScope::ThisValue;
value.tokvalue = tok2;
value.errorPath.push_back({tok2, "Lambda captures the 'this' variable here."});
value.errorPath.emplace_back(tok2, "Lambda captures the 'this' variable here.");
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected for clang-tidy to detect this but maybe that check is still in review.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we have modernize-use-emplace disabled in our .clang-tidy config.

The detection of unnecessary temporary object was to clang-tidy just today: llvm/llvm-project@987f9cb

@firewave firewave marked this pull request as ready for review June 2, 2022 20:21
Copy link
Copy Markdown
Collaborator

@danmar danmar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@firewave firewave merged commit 4316884 into cppcheck-opensource:main Jul 20, 2022
@firewave firewave deleted the errorpath branch July 20, 2022 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants